package van.planifolia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import van.planifolia.mapper.UserDao;
import van.planifolia.pojo.User;
import van.planifolia.service.UserService;
import van.planifolia.vo.UserVo;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Intellij IDEA<br>
 * 用户Service层的实现类
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/10/10 14:41
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    /**
     * 引入dao
     */
    @Resource(name = "userDao")
    private UserDao userDao;

    /**
     * 用户的登录业务
     * @param username 用户账户
     * @param password 用户密码
     * @return 登录上去的用户信息
     */
    @Override
    public User userLogin(String username, String password) {
        return userDao.selectUserByNameAndPass(username,password);
    }

    /**
     * 获取条件下的全部的用户信息
     * @param pageIndex 分页的下标
     * @param pageSize 分页的页面大小
     * @param userVo 用户的请求对象
     * @return 封装好的用户info
     */
    @Override
    public PageInfo<User> getUserList(Integer pageIndex, Integer pageSize, UserVo userVo) {
        PageHelper.startPage(pageIndex,pageSize);
        return new PageInfo<>(userDao.selectAllUser(userVo.getUsername(), userVo.getNikename()));

    }

    @Override
    public int addUserMsg(User user) {
        return userDao.insertUser(user);
    }
}
